package com.zhkj.txg.module.order.adapter

import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.zhkj.txg.R
import com.zhkj.txg.module.order.entity.DeliveryEntity

class ShippingCompanyAdapter(
    val onSelect: (entity: DeliveryEntity) -> Unit
) :
    BaseQuickAdapter<DeliveryEntity, BaseViewHolder>(R.layout.item_shipping_company) {

    init {
        setOnItemClickListener { _, _, position ->
            if (selectedPosition != position) {
                selectedPosition = position
                notifyDataSetChanged()
                onSelect(data[position])
            }
        }
    }

    private var selectedPosition = 0

    override fun convert(helper: BaseViewHolder, item: DeliveryEntity) {
        helper.setText(R.id.tvShippingCompany, item.name)
        helper.itemView.isSelected = selectedPosition == helper.layoutPosition
    }
}